package com.handpay.zztong.hp;


import android.os.Bundle;
import android.view.View;
import android.widget.TableRow;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.framework.utils.DateUtils;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.bean.AppealInfo;

import java.util.Hashtable;

public class AppealResponseActivity extends ZZTongActivity {

    private AppealInfo mAppealInfo;
    private TextView appeal_sn_tv;
    private TextView appeal_time_tv;
    private TextView appeal_status_tv;
    private TextView appeal_content_tv;
    private TextView appeal_reply_time_tv, trans_status_tv, trans_outcard_tv;
    private TextView appeal_reply_content_tv, appeal_trans_sn, appeal_trans_time, appeal_trans_amount_tv,appeal_type_tv;
    private TableRow appeal_reply_content_tr, appeal_reply_content_body_tr;
    private TableRow appeal_reply_time_tr;
    private TableRow   appeal_content_body_tr,            appeal_content_tr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_appeal_response);
        super.onCreate(savedInstanceState);
        mAppealInfo = (AppealInfo) this.getIntent().getSerializableExtra(ACTION);
        appeal_content_body_tr = (TableRow) this.findViewById(R.id.appeal_content_body_tr);
        appeal_content_tr = (TableRow) this.findViewById(R.id.appeal_content_tr);
        appeal_reply_content_tr = (TableRow) this.findViewById(R.id.appeal_reply_content_tr);
        appeal_reply_content_body_tr = (TableRow) this.findViewById(R.id.appeal_reply_content_body_tr);
        appeal_reply_time_tr = (TableRow) this.findViewById(R.id.appeal_reply_time_tr);
        //申诉编号
        appeal_sn_tv = (TextView) this.findViewById(R.id.appeal_sn_tv);
        //申诉时间
        appeal_time_tv = (TextView) this.findViewById(R.id.appeal_time_tv);
        //申诉类型
        appeal_type_tv  = (TextView) this.findViewById(R.id.appeal_type_tv);
        //申诉内容
        appeal_content_tv = (TextView) this.findViewById(R.id.appeal_content_tv);
        appeal_status_tv = (TextView) this.findViewById(R.id.appeal_status_tv);
        appeal_reply_time_tv = (TextView) this.findViewById(R.id.appeal_reply_time_tv);
        appeal_reply_content_tv = (TextView) this.findViewById(R.id.appeal_reply_content_tv);
        appeal_trans_sn = (TextView) this.findViewById(R.id.appeal_trans_sn_tv);
        appeal_trans_time = (TextView) this.findViewById(R.id.appeal_trans_time_tv);
        appeal_trans_amount_tv = (TextView) this.findViewById(R.id.appeal_trans_amount_tv);
        trans_status_tv = (TextView) this.findViewById(R.id.trans_status_tv);
        trans_outcard_tv = (TextView) this.findViewById(R.id.appeal_trans_outcard_tv);
        appeal_sn_tv.setText(mAppealInfo.getAppealId());
        appeal_time_tv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(mAppealInfo.getAppealTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
        String _appealType;
        if (mAppealInfo.getAppealType() == 0) {
            _appealType = "交易款项未到账";
            appeal_content_body_tr.setVisibility(View.GONE);
            appeal_content_tr.setVisibility(View.GONE);
        } else if (mAppealInfo.getAppealType() == 1) {
            _appealType = "交易手续费计算错误";
            appeal_content_body_tr.setVisibility(View.GONE);
            appeal_content_tr.setVisibility(View.GONE);
        }else  {
            _appealType = "其他";
            appeal_content_tv.setText(mAppealInfo.getAppealContent().replace("&", "\n"));
        }
        appeal_type_tv.setText(_appealType);

        //1：已申诉待回复
        //2：已回复
        String _appealStatus;
        if (mAppealInfo.getAppealStatus() == 0) {
            _appealStatus = "已申诉待回复";
        } else {
            _appealStatus = "已回复";
        }
        appeal_status_tv.setText(_appealStatus);


        if (mAppealInfo.getAppealStatus() == 0) {
            appeal_reply_content_tr.setVisibility(View.GONE);
            appeal_reply_content_body_tr.setVisibility(View.GONE);
            appeal_reply_time_tr.setVisibility(View.GONE);
        } else {
            appeal_reply_time_tv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(mAppealInfo.getReplyTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
            appeal_reply_content_tv.setText(mAppealInfo.getReplyContent().replace("&", "\n"));
        }
        appeal_trans_sn.setText(mAppealInfo.getTransSN());
        if (!"null".equals(mAppealInfo.getTransferAmount())) {
            appeal_trans_amount_tv.setText(CommonUtils.formatMoney(Double.valueOf(mAppealInfo.getTransferAmount()) / 100));
        }
        appeal_trans_time.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(mAppealInfo.getTransTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
        trans_outcard_tv.setText(CommonUtils.formatCard(mAppealInfo.getOutputCardNo()));
        String tranStatus;
        if (mAppealInfo.getPaymentStatus() == 0) {
            tranStatus = "交易失败";
        } else if (mAppealInfo.getPaymentStatus() == 1) {
            tranStatus = "交易成功";
        } else {
            tranStatus = "交易处理中";
        }
        trans_status_tv.setText(tranStatus);
    }


    private void initView() {

    }

    /***
     * 账账通账户退出
     */
    private void doTransactionAppeal() {
//		if (AccountUtils.getAccountPhone() == null)
//			return;
//		Hashtable<String, String> params = new Hashtable<String, String>();
//
//		params.put("channel", ClientEngine.CHANNEL);
//		if (mCurrentAppealType == APPEAL_STATUS_THREE){
//			params.put("appealType", "2");
//			params.put("appealContent", ClientEngine.CHANNEL);
//		}else if (mCurrentAppealType == APPEAL_STATUS_ONE){
//			params.put("appealType", "0");
//		}else if (mCurrentAppealType == APPEAL_STATUS_TWO){
//			params.put("appealType", "1");
//		}
//		params.put("status", "1");
//		params.put("transTime", mBill.getTransTime());
//		params.put("transSN", mBill.getTransSN());
//		doPost(this, Do_TransactionAppeal, params);
    }

    @Override
    public ActionBar getActivityActionBar() {
        return new ActionBar(getString(R.string.appeal_response_title), true);
    }



    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.appeal_btn) {
//			doTransactionAppeal();
        }
    }
}
